import numpy as np
import matplotlib.pyplot as plt

def rastrigin(x):
    A = 10
    return A + x**2 - A * np.cos(2 * np.pi * x)

x = np.linspace(-3, 0, 400)
y = rastrigin(x)

plt.plot(x, y)

plt.scatter(-1,rastrigin(-1),s=50,color='red',label='123123')
plt.scatter(-1.255,rastrigin(-1.255),s=50,color='red',label='123123')

plt.xlabel('X')
plt.ylabel('Rastrigin(X)')
plt.title('Rastrigin Function')
plt.grid(True)

plt.pause(1)  # 等待1秒

# 清除之前的图像并重新绘制
plt.clf()

plt.show()
